import java.util.ArrayList;
import java.util.Random;

import javax.swing.JTextArea;


public class Buff extends Ability {
	
	private String attackName;
	
	public Buff(double a, int b, int c, String d, String e, int ... procchance) {
		super(a, b, c, e, procchance);
		attackName = d;
	}
	
	public void addEffects(StatusEffect ... effects) {
		for (StatusEffect i : effects) {
			Effects.add(i);
		}
	}
	
	public void Fire(Player player, Character Target, JTextArea output, int playerTurns) {
		
		if (checkCooldown(playerTurns) == false) {
				int hitRoll = random.nextInt(100);
				double damage = (calcDamage(player));
				if (dmg_modifier > 0) {
					attackName = attackName + "You are healed for " + damage + ".\n";
					player.modifyCurrentHP(damage);
				} else {
					attackName = attackName + "\n";
				}
				player.modifyActionPoints(calcMove_Cost(player));
				output.append(attackName);
				TimerStart = playerTurns;
				this.checkCooldown(playerTurns);
				if (hitRoll < proc_chance) {	
					for (StatusEffect a : Effects) {
						player.addEffect(a);
						a.setStartTime(playerTurns);
					}
				}
			}else {
			output.append("This ability is on cooldown!\n");
		}
	}
	
	public void FireNPC(Player player, Character Target, JTextArea output, int opponentTurns) {
		double Damage = 0.0;
		String attackName;
		
		Damage = (calcDamageNPC(Target) * player.getArmourRating());
		attackName = (Target.getName() + "'s " + Name);
		if (dmg_modifier == 0) {
			attackName = attackName + " hits you.\n";
		} else {
		attackName = attackName + " hits you for " + (int) Math.rint(Damage) + " damage.\n";
		}
		int hitRoll = random.nextInt(100);
		if (hitRoll < 80) {
			if (hitRoll > player.ChanceToDodge()) {
				if (hitRoll > player.ChanceToParry(player.get_Main_Hand().getWeaponType())) {
					player.modifyCurrentHP(Damage * -1);
					Target.modifyActionPoints(calcMove_Cost(Target));
					output.append(attackName);
					TimerStart_NPC = opponentTurns;
					for (StatusEffect a : Effects) {
						a.setStartTime(TimerStart_NPC);
						player.addEffect(a);
					}
				} else {
					output.append("You parry " + Target.getName() + "'s attack, absorbing " + player.parryAmount() + " damage.\n");
					double dmgAmt = Damage - player.parryAmount();
					if (dmgAmt < 0) {
						dmgAmt = 0;
					}
					player.modifyCurrentHP((0 - dmgAmt));
					Target.modifyActionPoints(base_move_cost);
					TimerStart_NPC = opponentTurns;

				}

			} else {
				output.append(Target.getName() + " tries to strike you but you dodge!\n");
				Target.modifyActionPoints(base_move_cost);
				TimerStart_NPC = opponentTurns;
			}
		} else {
			output.append(Target.getName() + " swings at you but misses!\n");
			Target.modifyActionPoints(base_move_cost);
			TimerStart_NPC = opponentTurns;
		}
	}
	
	public int calcDamage(Player player) {
		int result = 0;
		double CalculatedDmg = ((player.get_Main_Hand().calcDamage(player)) * dmg_modifier);
		result = (int) Math.rint(CalculatedDmg);
		return result;
	}
	
	public int calcDamageNPC(Character NPC) {
		int result = 0;
		double CalculatedDmg = ((NPC.get_Main_Hand().calcDamage(NPC)) * dmg_modifier);
		result = (int) Math.rint(CalculatedDmg);
		return result;
	}
	
	public double calcMove_Cost(Player player) {
		double player_modifier = ((100.0 - player.getAgility()) / 100);
		double base_player_Move_Cost = (base_move_cost * player_modifier);
		double player_strength_modifier = ((100.00 - player.getStrength()) / 100);
		double weapon_weight_cost = (((player.get_Main_Hand().getWeight() * 2)) * player_strength_modifier) * -1;
		double armour_weight_cost = ((player.getArmourWeight() * player_strength_modifier) * -1);
		double Move_Cost = (base_player_Move_Cost + weapon_weight_cost + armour_weight_cost);

		return Move_Cost;
	}
	
	public double calcMove_Cost(Character NPC) {
		double player_modifier = ((100.0 - NPC.getAgility()) / 100);
		double base_player_Move_Cost = (base_move_cost * player_modifier);
		double player_strength_modifier = ((100.00 - NPC.getStrength()) / 100);
		double weapon_weight_cost = (((NPC.get_Main_Hand().getWeight() * 2)) * player_strength_modifier) * -1;
		double armour_weight_cost = ((NPC.getArmourWeight() * player_strength_modifier) * -1);
		double Move_Cost = (base_player_Move_Cost + weapon_weight_cost + armour_weight_cost);

		return Move_Cost;
	}
	
}
